package com.example.net.interceptor;

import java.io.IOException;

import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * 创建者     ZCL
 * 创建时间   2018/3/21 14:32
 * 描述	      ${TODO}
 * <p>
 * 更新者     $Author$
 * 更新时间   $Date$
 * 更新描述   ${TODO}
 */

public class AppendUrlInterceptor implements Interceptor {
    @Override
    public Response intercept(Chain chain) throws IOException {
        //得到元request
        Request request = chain.request();
        //拿到request里的url的那些信息的builder
        HttpUrl.Builder builder = request.url().newBuilder();
        //将原builder信息追加参数获得新的url
        HttpUrl newUrl = builder.addQueryParameter("deviceId", "zcl123")
                .addQueryParameter("token", "zhangchuanliu")
                .addQueryParameter("appVer", "1.0.0_beta")
                .build();
        //利用原来的request通过newBuilder创建新的request添加新的url
        Request newRequest = request.newBuilder().url(newUrl).build();
        //将request重新发送出去
        return chain.proceed(newRequest);

    }
}
